<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<%@include file="/comm/pub.inc"%>
		<script type="text/javascript" src="pub.js" ></script>
		<script type="text/javascript">
			var ROLE_DATA;
			function toGrantMenu(){
				//设置数据
				var datas = getSelectData();
				if (datas.length != 1){
					mini.alert("请选择一条数据!");
					return;
				}
				ROLE_DATA = datas[0];
				loadChecked(getMenusByRole(ROLE_DATA && ROLE_DATA.id));
				mini.get('grantWin').show();
			}
			function loadChecked(data){
	    		if (NOT_EMPTY(data)){
	    			var sb = [];
		    		for(var i=0;i<data.length;i++){
		    			sb.push(data[i].id+"");
		    		}
		    		mini.get('treeMenu').setValue(sb.join(','));
	    		}
	    	}
	    	function getMenusByRole(i){
	    		var json;
	    		$.ajax({
	    			url:contextPath+"/action/system/menu/getRoleMenus?id=1",
	    			async:false,
	    			dataType:"json",
	    			type:"get",
	    			success:function(j){
	    				json = 	j;
	    			}
	    		});
	    		return json;
	    	}
	    	function saveGrantMenu(){
				var checkList = mini.get('treeMenu').getCheckedNodes(true),
					menuIdList = [];
				$.each(checkList,function(){
					menuIdList.push(this.id);
				});
				var jsonData = {id:ROLE_DATA.id,menus:menuIdList};
				submitData(contextPath+"/action/system/role/grantMenu",
							{jsonData:mini.encode(jsonData)},closeGrantWin);
	    	}
	    	function closeGrantWin(){
	    		mini.get('grantWin').hide();
	    	}
		</script>
	</head>
	<body>
		<div id="queryForm" >
			<div style="width:700px;" >
				<table class="input-table" style="margin-left:0;" >
					<tr>
						<td >角色名：</td>
						<td><input style="width:200px;" type="text" class="mini-textbox" name="loginName"/>
						</td>
						<td>状态：</td>
						<td>
							<input name="status" class="mini-combobox" style="width:100%;" textField="name" valueField="id" data='[{id:"1",name:"是"},{id:"0",name:"否"}]' />
						</td>
						<td><a class="mini-button" iconCls="icon-search" onclick="search()" >查询</a></td>
						<td></td>
					</tr>
				</table>
			</div>
		</div>
		<div style="width:100%;">
		        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                        <a class="mini-button" iconCls="icon-add" onclick="toAddWin({status:1})" plain="true">新增</a>
		                        <a class="mini-button" iconCls="icon-edit" onclick="toEditWin" plain="true">编辑</a>
		                        <a class="mini-button" iconCls="icon-edit"
		                         onclick="deleteData('<%=contextPath %>/action/system/role/delete')" plain="true">删除</a>
		                        <a class="mini-button" iconCls="icon-edit" onclick="toGrantMenu" plain="true">分配菜单</a>
		                    </td>
		                    
		                </tr>
		            </table>           
		        </div>
		    </div>
			<div id="dataGrid" url="<%=contextPath %>/action/system/role/page" class="mini-datagrid"
				 style="width:100%;height:400px;" idField="id"
				multiSelect="false" sizeList="[20,40,80]" pageSize="20" >
					<div property="columns">
							<div type="checkcolumn" ></div>
							<div type="indexcolumn" headAlign=center >序号</div> 
							<div field="id" width="120" visible=false >id</div>   
							<div field="roleName" name="roleName" width="120">角色名称
							</div>
							<div field="roleDesc" name="roleDesc" width="120">角色描述
							</div>
							<div field="status" name="status" width="120" renderer="statusRender">是否可用</div>
					</div>
			</div>
		<!-- 添加功能窗口 -->
		<div id="addWin" class="mini-window" title="添加角色" iconCls="icon-add" style="width:600px;height:300px;overflow:hidden;" 
   			showMaxButton="false" showToolbar="false" showFooter="true" showModal="true" 
   			 allowResize="false" allowDrag="true"  >
   			 <table class="input-table" id="addForm" action="<%=contextPath %>/action/system/role/add"  >
   			 	<tr>
   			 		<td width=80 ><label>角色名称：</label></td>
   			 		<td><input name="roleName" class="mini-textbox"  maxLength="20" style="width:100%" emptyText="必填" requiredErrorText="不能为空" required /></td>
   			 		<td><label>描述：</label></td>
   			 		<td><input name="roleDesc"  class="mini-textbox" maxLength="25" style="width:100%" emptyText="必填" requiredErrorText="不能为空" required /></td>
   			 	</tr>
   			 	<tr>
   			 		<td><label>是否可用：</label></td>
   			 		<td>
   			 			<input name="status" class="mini-combobox" style="width:100%;" textField="name" valueField="id" data='[{id:"1",name:"是"},{id:"0",name:"否"}]' />
   			 		</td>
   			 	</tr>
   			 </table>
   			 <div property="footer" align="center" >
		        <a class="mini-button" iconCls="icon-save" onclick="saveAddData" >保存</a>
		        <a class="mini-button" iconCls="icon-close" onclick="closeAddWin" >关闭</a>
		    </div>
		</div>
		<!-- 修改功能窗口 -->
		<div id="editWin" class="mini-window" title="修改用户" iconCls="icon-add" style="width:600px;height:300px;overflow:hidden;" 
   			showMaxButton="false" showToolbar="false" showFooter="true" showModal="true" 
   			 allowResize="false" allowDrag="true" >
   			 <table class="input-table" id="editForm" action="<%=contextPath %>/action/system/role/modify" >
   			 	<tr>
   			 		<td width=80 ><label>角色名称：</label><input class="mini-hidden" name="id"  /></td>
   			 		<td><input name="roleName" class="mini-textbox" maxLength="20" style="width:100%" emptyText="必填" requiredErrorText="不能为空" required /></td>
   			 		<td><label>描述：</label></td>
   			 		<td><input name="roleDesc"  class="mini-textbox" maxLength="25" style="width:100%" emptyText="必填" requiredErrorText="不能为空" required /></td>
   			 	</tr>
   			 	<tr>
   			 		<td><label>是否可用：</label></td>
   			 		<td>
   			 			<input name="status" class="mini-combobox" style="width:100%;" textField="name" valueField="id" data='[{id:"1",name:"是"},{id:"0",name:"否"}]' />
   			 		</td>
   			 	</tr>
   			 </table>
   			 <div property="footer" align="center" >
		        <a class="mini-button" iconCls="icon-save" onclick="saveEditData" >保存</a>
		        <a class="mini-button" iconCls="icon-close" onclick="closeEditWin" >关闭</a>
		    </div>
		</div>
		<!-- 分配菜单窗口 -->
		<div id="grantWin" class="mini-window" title="分配菜单" iconCls="icon-node" style="width:400px;height:400px;overflow:hidden;" 
   			showMaxButton="false" showToolbar="false" showFooter="true" showModal="true" 
   			 allowResize="false" allowDrag="true" >
   			<ul id="treeMenu" class="mini-tree" 
				url="<%=contextPath %>/action/system/menu/query"
				style="width:350px;height:300px;padding:5px;overflow: auto;" 
		        showTreeIcon="true" textField="name" idField="id" parentField="parentId" resultAsTree="false" 
		        showCheckBox="true" checkRecursive="true"
		        allowSelect="false" enableHotTrack="false" >
			</ul> 
   			<div property="footer" >
		        <a class="mini-button" iconCls="icon-save" onclick="saveGrantMenu()" >保存</a>
		        <a class="mini-button" iconCls="icon-close" onclick="closeGrantWin" >关闭</a>
		    </div>
		</div>
	</body>
</html>
